package com.practice.concurrent;


import java.util.ArrayList;
import java.util.List;


public class TestAQS {

    public static void main(String[] args) throws InterruptedException {
        int[] count = new int[]{1000};
        List<Thread> threadList = new ArrayList<>();
        AQSLock lock = new AQSLock();
        for (int i = 0; i < 5; i++) {
            threadList.add(new Thread(() -> {
                for(int k=0;k<5;k++){
                    lock.lock();
                }
                for (int j = 0; j < 10; j++) {
                    count[0]--;
                }
                for(int k=0;k<5;k++){
                    lock.unlock();
                }
            }));
        }
        for (Thread thread : threadList) {
            thread.start();
        }
        for (Thread thread : threadList) {
            thread.join();
        }
        System.out.println(count[0]);
    }
}
